 //
//  ZSRefreshView.swift
//  刷新控件
//
//  Created by macssss on 16/7/9.
//  Copyright © 2016年 macssss. All rights reserved.
//

import UIKit

//MARK: -  刷新视图
 
class ZSRefreshView: UIView {
    
    //刷新默认状态
    var refreshState: ZSRefreshState = .Normal {
        
        didSet {
            
            switch refreshState {
            case .Normal:
                //恢复状态
                tipIcon?.isHidden = false
                indicator?.startAnimating()
                
                tipLabel?.text = "继续下拉"
                UIView.animate(withDuration: 0.25 ) {
                    
                    self.tipIcon?.transform = CGAffineTransform.identity
                }
                
            case .Pulling:
                tipLabel?.text = "放手刷新"
                //
                UIView.animate(withDuration: 0.25) {
                    //箭头翻转 根据动画旋转就近原则 把一边设置小一点就好了
                    self.tipIcon?.transform = CGAffineTransform(rotationAngle: CGFloat(M_PI + 0.001))
                }
            case .WillRefresh:
                tipLabel?.text = "正在刷新"
                //正在刷新隐藏箭头
                tipIcon?.isHidden = true
                //显示菊花
                indicator?.startAnimating()
                
                
            }
            
        }
        
    }

   //箭头图像
    @IBOutlet weak var tipIcon: UIImageView?
    //刷新文字
    @IBOutlet weak var tipLabel: UILabel?
    //指示器 菊花
    @IBOutlet weak var indicator: UIActivityIndicatorView?
 
    /// 父视图的高度 - 为了刷新控件不需要关心当前具体的刷新视图是谁！
    var parentViewHeigth: CGFloat = 0

    class func refreshView() -> ZSRefreshView {

        let nib = UINib(nibName: "ZSMeituanRefreshView", bundle: nil)

        return nib.instantiate(withOwner: nil, options: nil)[0] as! ZSRefreshView
        
    }
 
}
